//
//  ZYWelcomeViewController.swift
//  WBBeta1
//
//  Created by wustzhy on 16/8/11.
//  Copyright © 2016年 Yestin. All rights reserved.
//

import UIKit
//import SDWebImage


class ZYWelcomeViewController: UIViewController {
    
    override func viewDidAppear(animated: Bool) {
    //在viewDidAppear后 头像动起来
        super.viewDidAppear(animated)
        headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(view).offset(100)
        }
        //阻尼damp 动画方法
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
                self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.messageLabel.alpha = 1
                }, completion: { (_) -> Void in
                    //欢迎动画完毕，发送通知－－进入mainVC界面
                  NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICATION, object: nil)
                })
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
    }
    
    private func setupUI(){
        view.addSubview(bjImageView)
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
        //设置约束
        bjImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
        }
        headImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(headImageView.snp_bottom).offset(16)
            make.centerX.width.equalTo(headImageView)
        }
    }
    
    // MARK: - 懒加载控件
    private lazy var bjImageView:UIImageView = UIImageView(imgName: "ad_background")
    private lazy var headImageView:UIImageView = {
       let img = UIImageView(imgName: "avatar_default_big")
//        img.sd_setImageWithURL(NSURL(string: ZYUserAccountViewModel.sharedTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
            //用自己封装的
//        img.zy_setImageWithString(ZYUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        return img
    }()
    private lazy var messageLabel: UILabel = {
        let lab = UILabel()
        lab.font = UIFont.systemFontOfSize(18)
        lab.text = "欢迎回来"
        lab.textColor = UIColor.darkGrayColor()
        lab.textAlignment = .Center
        lab.alpha = 0
        return lab
    }()
}
